//
// Created by Administrator on 2023/11/21.
//
#include "bits/stdc++.h"
using namespace std;

const int N=110;

struct S{
    int no;
    int g;
    bool operator <(const S &M)const{
        if(g==M.g)
            return no<M.no;
        else
            return g<M.g;
    }
}s[N];

int main(){
    int n;
    cin>>n;
    for (int i = 0; i < n; ++i) {
        cin>>s[i].no>>s[i].g;
    }
    sort(s,s+n);
    for (int i = 0; i < n; ++i) {
        cout<<s[i].no<<" "<<s[i].g<<endl;
    }
}